{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b34d92bb-ee2f-4d45-999c-159951b8f689",
   "metadata": {},
   "outputs": [],
   "source": [
    "import camelot\n",
    "\n",
    "# 参数 process_background=True 时，与 flavor='stream' 会不兼容\n",
    "\n",
    "tables = camelot.read_pdf('./test.pdf',flavor='stream',pages='all')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "706f3012-8ab6-42ea-ae5d-bb4c5f847972",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "共有 12 张报表，第 1 张报表已生成……\n",
      "共有 12 张报表，第 2 张报表已生成……\n",
      "共有 12 张报表，第 3 张报表已生成……\n",
      "共有 12 张报表，第 4 张报表已生成……\n",
      "共有 12 张报表，第 5 张报表已生成……\n",
      "共有 12 张报表，第 6 张报表已生成……\n",
      "共有 12 张报表，第 7 张报表已生成……\n",
      "共有 12 张报表，第 8 张报表已生成……\n",
      "共有 12 张报表，第 9 张报表已生成……\n",
      "共有 12 张报表，第 10 张报表已生成……\n",
      "共有 12 张报表，第 11 张报表已生成……\n",
      "共有 12 张报表，第 12 张报表已生成……\n"
     ]
    }
   ],
   "source": [
    "for i,table in enumerate(tables):\n",
    "    table.to_excel(f'table_{i + 1}.xlsx',index=False,header=None)\n",
    "    print(f'共有 {len(tables)} 张报表，第 {i + 1} 张报表已生成……')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
